![]() |
PATH![]() |
![]() ![]() |
The Get command can function as an AppleScript command or an application command. The AppleScript command returns the value of an expression. The application command returns the value of an object. In both cases, the command assigns the value returned to the predefined variable result , which is described in Using the Predefined Result Variable.
If no error is generated, the result is the value of the specified reference or expression.
If the referenceToObject parameter specifies a single object only (such as word 1 or the last word ), the result is a single value. If the specified object doesn't exist, for example, if the reference is word 12 and there are fewer than 12 words in the specified container, AppleScript generates an error.
If the referenceToObject parameter uses a whose clause (such as the words whose first character is "B" ) to specify the object or objects to get, the result is always a list. If the specified objects don't exist (for example, if the reference is the words whose first character is "B" and there are no words that begin with "B"), the result is an empty list.
Class: The class specified by the className parameter or a list of values of that class. The application can use this parameter to determine what kind of data to return. For example, an application may return text in various formats. Note that if necessary, AppleScript attempts to coerce the result into the class specified by this parameter.
Figure 4-1 The AppleWorks document "Simple"
tell document "Simple" of application "AppleWorks"
get paragraph 3 of text body
end tell
--result (for doc in Figure 4-1): "This is paragraph three."
The word get in the Get command is optional because AppleScript automatically gets the value of expressions and references when they appear in scripts.
For example, the following statements are equivalent:
item 1 of {"Hi,", "how", "are", "you?"}
--result: "Hi,"
get item 1 of {"Hi,", "how", "are", "you?"}
--result: "Hi,"
The following statements are also equivalent:
tell application "AppleWorks"
word 1 of text body of document "Introduction"
end tell
tell application "AppleWorks"
get word 1 of text body of document "Introduction"
end tell